<?php
namespace app\admin\controller;

use app\admin\traits\Result;
use think\facade\Request;
use app\common\model\From as FromModel;


class From extends Common
{
    
    

    //列表
    public function index(){

        if ($this->request->isAjax()) {
            $data = [
                'key' => $this->request->get('key', '', 'trim'),
                'limit' => $this->request->get('limit', 10, 'intval'),
            ];

            $list = FromModel::where('type',1)->withSearch(['title'], ['title' => $data['key']])->order('id desc')
                ->paginate($data['limit'], false, ['query' => $data]);
            // dump(Zhuanqu::getlastsql());die;
            $user_date = [];
            foreach ($list as $key => $val) {
                $user_date[$key] = $val;
            }

            return show($user_date, 0, '', ['count' => $list->total()]);
        }
        return $this->fetch();

    }
 

    public function del(){
        $id = $this->request->param('id', 0, 'intval');
        if ($id) {
            $res = FromModel::where('id='.$id)->delete();
            if ($res) {
                $msg = Result::success('删除成功');
            } else {
                $msg = Result::error('删除失败');
            }

            return $msg;

        } else {
            $this->error('参数错误');
        }

    }
	
	public function index_two(){

        if ($this->request->isAjax()) {
            $data = [
                'key' => $this->request->get('key', '', 'trim'),
                'limit' => $this->request->get('limit', 10, 'intval'),
            ];

            $list = FromModel::where('type',2)->withSearch(['title'], ['title' => $data['key']])->order('id desc')
                ->paginate($data['limit'], false, ['query' => $data]);
            // dump(Zhuanqu::getlastsql());die;
            $user_date = [];
            foreach ($list as $key => $val) {
                $user_date[$key] = $val;
            }

            return show($user_date, 0, '', ['count' => $list->total()]);
        }
        return $this->fetch();

    }
    
}



?>